package com.study.mapper;

import com.study.pojo.SysRole;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/**
 * @PackgeName: com.study.mapper
 * @ClassName: SysRoleMapper
 * @Author: 严志祥
 * Date: 2022-05-23 16:48
 * project name: MyBatis-01
 * @Version:
 * @Description:
 */
public interface SysRoleMapper {

    int insert(SysRole sysRole)throws SQLException;

    @Insert("insert into sys_role (role_id,role_code,role_name) values (#{roleId},#{roleCode},#{roleName})")
    int insert2(SysRole sysRole)throws SQLException;

    int update(SysRole sysRole)throws SQLException;

    @Update("update sys_role set role_code = #{roleCode},role_name = #{roleName} where role_id = #{roleId}")
    int update2(SysRole sysRole)throws SQLException;

    int delete(Integer roleId)throws SQLException;

    @Delete("delete from sys_role where role_id = #{roleId}")
    int delete2(Integer roleId)throws SQLException;

    /**
     *解决查询字段不一致的三种方式
     * 1、起别名
     * 2、在核心配置文件中开启驼峰命名规则
     * 3、配置resultMap
     */
    SysRole select1()throws SQLException;

    @Select("select * from sys_role limit 1")
    SysRole select10()throws SQLException;

    List<SysRole> select2();

    @Select("select * from sys_role limit 2")
    List<SysRole> select20();

    @Select("select role_name from sys_role where role_id = #{roleId}")
    String selectByName(Integer roleId)throws SQLException;

    String selectByName2(Integer roleId)throws SQLException;

    @Select("select * from sys_role limit 1")
    Map<String,Object> selectByMap();

    @Select("select * from sys_role limit 2")
    List<Map<Integer,Object>> selectByMap2()throws SQLException;

    @Select("select role_id as roleId,role_code as roleCode,role_name as roleName from sys_role where role_id = #{roleId}")
    SysRole SelectById(Integer roleId)throws SQLException;
}
